<style lang="less">
@import "../less/editable-table.less";
</style>

<template>
    <div>
        <Table border :columns="columns" :data="tableData"></Table>
        <Modal v-model="removeModel" width="360">
            <p slot="header" style="color:#f60;">
                <Icon type="information-circled"></Icon>
                <span>删除提示</span>
            </p>
            <div style="text-align:center">
                <p style="font-size:18px;">数据删除后不可恢复，请谨慎操作！</p>
            </div>
            <div slot="footer">
                <Button type="error" @click="remove()" size="large">删除</Button>
                <Button type="info" @click="noRemove()" size="large">取消</Button>
            </div>
        </Modal>
    </div>
</template>

<script>
import ajax from '../../../../libs/axios.js'
export default {
    props: {
        tableData: Array,
        access: Object
    },
    data () {
        return {
            removeModel:false,       // 删除弹窗
            partyModel: false,
            id: '',                  // id
            partySection: {},
            itemTotal: 0,            // 条数
            columns: [
                {
                    title: '#',
                    type: 'index',
                    width: 50,
                    align: 'center'
                },
                {
                    title: '车型',
                    align: 'center',
                    width: 260,
                    key: 'model'
                },
                {
                    title: '规格',
                    align: 'center',
                    width: 65,
                    key: 'specification'
                },
                {
                    title: '指导价',
                    align: 'center',
                    width: 80,
                    key: 'guidance_PRICE'
                },
                {
                    title: '状态',
                    align: 'center',
                    width: 65,
                    key: 'car_STATUS'
                },
                {
                    title: '主体名称',
                    align: 'center',
                    width: 100,
                    key: 'party_NAME'
                },
                {
                    title: '人员名称',
                    align: 'center',
                    width: 90,
                    key: 'login_NAME'
                },
                {
                    title: '车架号',
                    align: 'center',
                    width: 90,
                    key: 'vin'
                },
                {
                    title: '外观',
                    align: 'center',
                    width: 90,
                    key: 'out_COLOR'
                },
                {
                    title: '内饰',
                    align: 'center',
                    width: 90,
                    key: 'in_COLOR'
                },
                {
                    title: '所在地',
                    align: 'center',
                    width: 100,
                    key: 'car_LOCATION'
                },
                {
                    title: '状态',
                    align: 'center',
                    width: 100,
                    key: 'status',
                    render: (h, params) => {
                        if (params.row.status === -1) {
                            return h('span', '删除')
                        }else if(params.row.status === 0) {
                            return h('span', '未审核')
                        }else if(params.row.status === 1) {
                            return h('span', '下架')
                        }else if(params.row.status === 2) {
                            return h('span', '上架')
                        }else if(params.row.status === 3) {
                            return h('span', '推荐')
                        }
                    }
                },
                {
                    title: '创建时间',
                    align: 'center',
                     width: 150,
                    key: 'create_TIME'
                },
                {
                    title: '操作',
                    key: 'action',
                    align: 'center',
                    width: 170,
                    fixed: 'right',
                    render: (h, params) => {
                        return h('div', [
                            h(
                                'Button',
                                {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '1px',
                                        display: (params.row.status == 0) || (params.row.status == 1) ? 'inline-block' : 'none'
                                    },
                                    on: {
                                        click: () => {
                                            this.goRemove(params.index, params.row.id)
                                        }
                                    }
                                },
                                '删除'
                            ),
                            h(
                                'Button',
                                {
                                    props: {
                                        type: 'info',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight:'1px',
                                        display: (params.row.status == 0) || (params.row.status == 1) ? 'inline-block' : 'none'
                                    },
                                    on: {
                                        click: () => {
                                             this.editData(params.row.id)
                                        }
                                    }
                                },
                                '修改'
                            ),
                            h(
                                'Button',
                                {
                                    props: {
                                        type: 'warning',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight:'1px',
                                        display: (params.row.status == 0) || (params.row.status == 1) ? 'inline-block' : 'none'
                                    },
                                    on: {
                                        click: () => {
                                             this.auditData(params.row.id,2)
                                        }
                                    }
                                },
                                '审核'
                            ),
                            h(
                                'Button',
                                {
                                    props: {
                                        type: 'info',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight:'1px',
                                        display: params.row.status == 2 ? 'inline-block' : 'none'
                                    },
                                    on: {
                                        click: () => {
                                             this.auditData(params.row.id,1)
                                        }
                                    }
                                },
                                '下架'
                            )
                        ])
                    }
                }
            ],
            partyData: [],
            data: [],
            partyId:''
        }
    },
    created () {
        this.init()
    },
    activated () {
        this.init()
    },
    methods: {
        // 初始化数据
        init () {
            this.partyData = [];
        },
        // 新增
        auditData (id,status) {
            let argu = {
                id: id,
                status:status
            }
            this.$router.push({
                name: 'auditcarsource',
                params: argu
            })
        },
        // 修改
        editData (id) {
            let argu = {
                id: id
            }
            this.$router.push({
                name: 'editcarsource',
                params: argu
            })
        },
        // 删除
        goRemove (index, id) {
            this.modal = true
            this.id = id
            this.index = index
            this.removeModel = true
        },
        // 删除确定
        remove () {
            let url = 'adminlogin/carsource/updateInfoById'
            let data = {
                ID: this.id,
                STATUS:-1
            }
            ajax.formRes(url, data).then(res => {
                    if (res.data > 0) {
                        this.tableData.splice(this.index, 1)
                        //this.tableData[this.index].status = 0;
                        this.removeModel = false
                    }
            }).catch(res => {
                console.log('有错误信息')
                // fail
            })
        },
        // 删除取消
        noRemove () {
            this.removeModel = false
        },
        // 取消
        cancel () {
            this.partySection = {}
            this.partyModel = false
        },
    },
}
</script>
